package books4africa

import static org.junit.Assert.*

import grails.test.mixin.*
import grails.test.mixin.support.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
 */
@TestMixin(GrailsUnitTestMixin)
class BookRequestTests {

    void testBookRequest(){
		
		BookRequest bookRequestTest = new BookRequest(requestDescription: "test", title: null, category: "category", gradeLower: 1, gradeHigher: 6, qty: 20, dateMinString: "min", dateMaxString: "max");
				
		//test: bookRequest doesn't have a title
		assertFalse(bookRequestTest.validate());
	
		//test: bookRequest doesn't have a category
		bookRequestTest.title = "Title";
		assertTrue bookRequestTest.validate(); //bookRequest should be correct here
		bookRequestTest.category = null;
		assertFalse(bookRequestTest.validate());
		
		//test: bookRequest has an incorrect gradeLower
		bookRequestTest.category = "category";
		bookRequestTest.gradeLower = -1;
		assertFalse(bookRequestTest.validate());
		bookRequestTest.gradeLower = 8;
		assertFalse(bookRequestTest.validate());
		
		//test: gradeLower lower bound is valid
		bookRequestTest.gradeLower = 0;
		assertTrue(bookRequestTest.validate());
		bookRequestTest.gradeLower = 6;
		assertTrue(bookRequestTest.validate());
		
		//test: bookRequest has an incorrect gradeHigher
		bookRequestTest.gradeHigher = -1;
		assertFalse(bookRequestTest.validate());
		bookRequestTest.gradeHigher = 8;
		assertFalse(bookRequestTest.validate());
		
		//test: gradeHigher higher bound is valid
		bookRequestTest.gradeHigher = 0;
		assertTrue(bookRequestTest.validate());
		bookRequestTest.gradeHigher = 6;
		assertTrue(bookRequestTest.validate());
		
		//test: bookRequest has invalid and valid qty 
		bookRequestTest.qty = 0;
		assertFalse(bookRequestTest.validate());
		bookRequestTest.qty = 501;
		assertFalse(bookRequestTest.validate());
		bookRequestTest.qty = 1;
		assertTrue(bookRequestTest.validate());
		bookRequestTest.qty = 500;
		assertTrue(bookRequestTest.validate());
		
		//test: bookRequest has a dateMinString
		bookRequestTest.dateMinString = null;
		assertFalse(bookRequestTest.validate());
		
		bookRequestTest.dateMinString = "min";
		//test: bookRequest has a dateMaxString
		bookRequestTest.dateMaxString = null;
		assertFalse(bookRequestTest.validate());
	}
}
